package com.iocollege.tinyframe.service.system.impl;

import com.iocollege.tinyframe.common.service.impl.BaseMyService;
import com.iocollege.tinyframe.common.utils.DictUtils;
import com.iocollege.tinyframe.entity.system.SysDictData;
import com.iocollege.tinyframe.mapper.system.SysConfigMapper;
import com.iocollege.tinyframe.mapper.system.SysDictDataMapper;
import com.iocollege.tinyframe.service.system.SysDictDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 字典数据表 服务实现类
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2021-04-07
 */
@Service
public class SysDictDataServiceImpl extends BaseMyService<SysDictDataMapper, SysDictData> implements SysDictDataService {


    /**
     * 新增保存字典数据信息
     *
     * @param dictData 字典数据信息
     * @return 结果
     */
    @Override
    public int insertDictData(SysDictData dictData)
    {
        SysDictDataMapper myMaper = (SysDictDataMapper)this.baseMapper;
        int row = myMaper.insert(dictData);
        if (row > 0)
        {
            DictUtils.clearDictCache();
        }
        return row;
    }

    /**
     * 修改保存字典数据信息
     *
     * @param dictData 字典数据信息
     * @return 结果
     */
    @Override
    public int updateDictData(SysDictData dictData)
    {

        SysDictDataMapper myMaper = (SysDictDataMapper)this.baseMapper;

        int row = myMaper.updateById(dictData);
        if (row > 0)
        {
            DictUtils.clearDictCache();
        }
        return row;
    }

    @Override
    public int removeByIds(Long[] dictCodes) {
        SysDictDataMapper myMaper = this.baseMapper;
        List<Long> longList = Arrays.asList(dictCodes);
        Integer row = this.baseMapper.deleteBatchIds(longList);

        if (row > 0)
        {
            DictUtils.clearDictCache();
        }
        return row;
    }

}
